
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
  
<!-- Mirrored from werkzeug.palletsprojects.com/en/1.0.x/middleware/http_proxy/ by HTTrack Website Copier/3.x [XR&CO'2014], Tue, 15 Sep 2020 06:37:09 GMT -->
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=Edge" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Basic HTTP Proxy &#8212; Werkzeug Documentation (1.0.x)</title>
    <link rel="stylesheet" href="../../_static/werkzeug.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
    <link rel="stylesheet" type="text/css" href="../../../../../assets.readthedocs.org/static/css/badge_only.css" />
    <script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script>
    <script type="text/javascript" src="../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../_static/doctools.js"></script>
    <script type="text/javascript" src="../../_static/language_data.js"></script>
    <script async="async" type="text/javascript" src="../../../../../assets.readthedocs.org/static/javascript/readthedocs-doc-embed.js"></script>
    <link rel="shortcut icon" href="../../_static/favicon.ico"/>
    <link rel="index" title="Index" href="../../genindex/index.html" />
    <link rel="search" title="Search" href="../../search/index.html" />
    <link rel="next" title="WSGI Protocol Linter" href="../lint/index.html" />
    <link rel="prev" title="Application Dispatcher" href="../dispatcher/index.html" />
    <link rel="canonical" href="index.html">
  <script>DOCUMENTATION_OPTIONS.URL_ROOT = '../../index.html';</script>
   
  
<!-- RTD Extra Head -->

<!-- 
Always link to the latest version, as canonical.
http://docs.readthedocs.org/en/latest/canonical.html
-->
<link rel="canonical" href="index.html" />

<link rel="stylesheet" href="../../../../../assets.readthedocs.org/static/css/readthedocs-doc-embed.css" type="text/css" />

<script type="text/javascript" src="../../_static/readthedocs-data.js"></script>

<!-- Add page-specific data, which must exist in the page js, not global -->
<script type="text/javascript">
READTHEDOCS_DATA['page'] = "middleware/http_proxy"
READTHEDOCS_DATA['source_suffix'] = ".rst"
</script>

<script type="text/javascript" src="../../../../../assets.readthedocs.org/static/javascript/readthedocs-analytics.js" async="async"></script>

<!-- end RTD <extrahead> -->
</head><body>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex/index.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../py-modindex/index.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="../lint/index.html" title="WSGI Protocol Linter"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="../dispatcher/index.html" title="Application Dispatcher"
             accesskey="P">previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../index.html">Werkzeug Documentation (1.0.x)</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../index.html" accesskey="U">Middleware</a> &#187;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <span class="target" id="module-werkzeug.middleware.http_proxy"></span><div class="section" id="basic-http-proxy">
<h1>Basic HTTP Proxy<a class="headerlink" href="#basic-http-proxy" title="Permalink to this headline">¶</a></h1>
<dl class="class">
<dt id="werkzeug.middleware.http_proxy.ProxyMiddleware">
<em class="property">class </em><code class="descclassname">werkzeug.middleware.http_proxy.</code><code class="descname">ProxyMiddleware</code><span class="sig-paren">(</span><em>app</em>, <em>targets</em>, <em>chunk_size=16384</em>, <em>timeout=10</em><span class="sig-paren">)</span><a class="headerlink" href="#werkzeug.middleware.http_proxy.ProxyMiddleware" title="Permalink to this definition">¶</a></dt>
<dd><p>Proxy requests under a path to an external server, routing other
requests to the app.</p>
<p>This middleware can only proxy HTTP requests, as that is the only
protocol handled by the WSGI server. Other protocols, such as
websocket requests, cannot be proxied at this layer. This should
only be used for development, in production a real proxying server
should be used.</p>
<p>The middleware takes a dict that maps a path prefix to a dict
describing the host to be proxied to:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">app</span> <span class="o">=</span> <span class="n">ProxyMiddleware</span><span class="p">(</span><span class="n">app</span><span class="p">,</span> <span class="p">{</span>
    <span class="s2">&quot;/static/&quot;</span><span class="p">:</span> <span class="p">{</span>
        <span class="s2">&quot;target&quot;</span><span class="p">:</span> <span class="s2">&quot;http://127.0.0.1:5001/&quot;</span><span class="p">,</span>
    <span class="p">}</span>
<span class="p">})</span>
</pre></div>
</div>
<p>Each host has the following options:</p>
<dl class="docutils">
<dt><code class="docutils literal notranslate"><span class="pre">target</span></code>:</dt>
<dd>The target URL to dispatch to. This is required.</dd>
<dt><code class="docutils literal notranslate"><span class="pre">remove_prefix</span></code>:</dt>
<dd>Whether to remove the prefix from the URL before dispatching it
to the target. The default is <code class="docutils literal notranslate"><span class="pre">False</span></code>.</dd>
<dt><code class="docutils literal notranslate"><span class="pre">host</span></code>:</dt>
<dd><dl class="first last docutils">
<dt><code class="docutils literal notranslate"><span class="pre">&quot;&lt;auto&gt;&quot;</span></code> (default):</dt>
<dd>The host header is automatically rewritten to the URL of the
target.</dd>
<dt><code class="docutils literal notranslate"><span class="pre">None</span></code>:</dt>
<dd>The host header is unmodified from the client request.</dd>
<dt>Any other value:</dt>
<dd>The host header is overwritten with the value.</dd>
</dl>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">headers</span></code>:</dt>
<dd>A dictionary of headers to be sent with the request to the
target. The default is <code class="docutils literal notranslate"><span class="pre">{}</span></code>.</dd>
<dt><code class="docutils literal notranslate"><span class="pre">ssl_context</span></code>:</dt>
<dd>A <a class="reference external" href="https://docs.python.org/3/library/ssl.html#ssl.SSLContext" title="(in Python v3.8)"><code class="xref py py-class docutils literal notranslate"><span class="pre">ssl.SSLContext</span></code></a> defining how to verify requests if the
target is HTTPS. The default is <code class="docutils literal notranslate"><span class="pre">None</span></code>.</dd>
</dl>
<p>In the example above, everything under <code class="docutils literal notranslate"><span class="pre">&quot;/static/&quot;</span></code> is proxied to
the server on port 5001. The host header is rewritten to the target,
and the <code class="docutils literal notranslate"><span class="pre">&quot;/static/&quot;</span></code> prefix is removed from the URLs.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>app</strong> – The WSGI application to wrap.</li>
<li><strong>targets</strong> – Proxy target configurations. See description above.</li>
<li><strong>chunk_size</strong> – Size of chunks to read from input stream and
write to target.</li>
<li><strong>timeout</strong> – Seconds before an operation to a target fails.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<details class="changelog">
<summary>Changelog</summary><div class="versionadded">
<p><span class="versionmodified">New in version 0.14.</span></p>
</div>
</details></dd></dl>

</div>


          </div>
        </div>
      </div>
  <span id="sidebar-top"></span>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
  
    
            <p class="logo"><a href="../../index.html">
              <img class="logo" src="../../_static/werkzeug.png" alt="Logo"/>
            </a></p>
  
<h3>Navigation</h3>
<ul>
  <li><a href="../../index.html">Overview</a>
    <ul>
      <li><a href="../index.html">Middleware</a>
        <ul>
          <li>Previous: <a href="../dispatcher/index.html" title="previous chapter">Application Dispatcher</a>
          <li>Next: <a href="../lint/index.html" title="next chapter">WSGI Protocol Linter</a></ul>
      </li>
    </ul>
  </li>
</ul>
<div id="searchbox" style="display: none" role="search">
  <h3>Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="https://werkzeug.palletsprojects.com/en/1.0.x/search/" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    </div>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
  
    <div class="footer" role="contentinfo">
        &#169; Copyright 2007 Pallets.
      Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.8.5.
    </div>
    <script>
      if (typeof READTHEDOCS_DATA !== 'undefined') {
        if (!READTHEDOCS_DATA.features) {
          READTHEDOCS_DATA.features = {};
        }
        READTHEDOCS_DATA.features.docsearch_disabled = true;
      }
    </script>

  </body>

<!-- Mirrored from werkzeug.palletsprojects.com/en/1.0.x/middleware/http_proxy/ by HTTrack Website Copier/3.x [XR&CO'2014], Tue, 15 Sep 2020 06:37:09 GMT -->
</html>